<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <!--    <div class="table-page-search-wrapper">-->
    <!--      <a-form layout="inline" @keyup.enter.native="searchQuery">-->
    <!--        <a-row :gutter="24">-->
    <!--        </a-row>-->
    <!--      </a-form>-->
    <!--    </div>-->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-button @click="handleAdd" type="primary" icon="plus" > 新增物资领用单</a-button>
      <div style="font-size: 16px;font-weight: 800;;margin-top: 20px">-历史数据查询</div>
      <a-form layout="inline" @keyup.enter.native="searchQuery" style="margin-top: 10px">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <a-input placeholder="请输入单据编号" v-model="queryParam.orderNo"></a-input>
            </a-form-item>
          </a-col>
          <a-form-item label="物资名称" :labelCol="labelCol" :wrapperCol="wrapperCol"  v-show="toggleSearchStatus ? true : false">
            <j-search-select-tag type="list" v-model="queryParam.assetId"
                                 :trigger-change="true" dict="zcgl_asset_fixed,name,id" :disabled="disableSubmit"
                                 placeholder="物资名称"/>
          </a-form-item>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <!--            <a-form-item label="入库部门">-->
            <!--              <a-input placeholder="请输入入库部门" v-model="queryParam.putDepartment"></a-input>-->
            <!--            </a-form-item>-->
            <a-form-item label="领用部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-depart v-model="queryParam.newDepartment"></j-select-depart>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="领用人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-cang-ku v-model="queryParam.recipientsUser"></j-select-cang-ku>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>

              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>


          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <!--            <a-form-item label="入库部门">-->
            <!--              <a-input placeholder="请输入入库部门" v-model="queryParam.putDepartment"></a-input>-->
            <!--            </a-form-item>-->
            <!--            <a-form-item label="物资" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
            <!--              <j-select-depart  v-model="queryParam.assetId"></j-select-depart>-->
            <!--            </a-form-item>-->


          </a-col>


        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

<!--      <a-button type="primary" icon="download" @click="handleExportXls('资产领用')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"-->
<!--                @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
<!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
<!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a-->
<!--        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
<!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
<!--      </div>-->
<!--      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"-->
      <a-table
        :customRow="click"
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"

        @change="handleTableChange1">



<!--        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"-->
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
<!--          <template>-->
<!--            <a   v-if="record.processStatus != 2 && record.processStatus != 1 && record.processStatus != 0"-->
<!--                  @click.stop="modifyForm(record, '生效审批')">-->
<!--              生效审批-->
<!--            </a>-->
<!--          </template>-->
             <a   @click.stop="chakan(record)">

                 查看
               </a>
          <!--            <a v-if="record.processStatus != 2 && record.processStatus != 1 && record.processStatus != 0"-->
          <!--               @click.stop="modifyForm(record, '生效审批')">-->
          <!--           生效审批-->
          <!--            </a>-->



<!--          <a-divider type="vertical"/>-->
<!--          <a-dropdown>-->
<!--            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a v-if="record.processStatus != 2 && record.processStatus != 1 && record.processStatus != 0">删除</a>-->
<!--                  <a v-if="record.processStatus == ''">删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
<!--            </a-menu>-->
<!--          </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <!--流程表单-->
    <a-modal :title="lcModa.title" v-model="lcModa.visible" :footer="null" :maskClosable="false" width="80%">
      <component  :title="lcModa.titleContent"   :disabled="lcModa.disabled" v-if="lcModa.visible" :is="lcModa.formComponent"
                 :processData="lcModa.processData" :isNew="lcModa.isNew"
                  @shuaxin="searchQuery"     @afterSubmit="processFormOk" @close="lcModa.visible=false, lcModa.disabled = false"></component>
    </a-modal>


    <zcglRecipients-modal   :addFlag="addFlag" :assetValue="queryParam.assetId" ref="modalForm" @ok="modalFormOk"></zcglRecipients-modal>
  </a-card>
</template>

<script>
import store from '@/store'
import { JeecgListMixin } from '@/mixins/componentMix'
import ZcglRecipientsModal from './modules/ZcglRecipientsModal'
import '@/assets/less/TableExpand.less'
import { activitiMixin } from '../activiti/mixins/activitiMixin'
import ZcglPutAssetAdd from '../activiti/form/ZcglPutAssetAdd'
import ZcglPutStorageModal from './modules/ZcglPutStorageModal'
import JSearchSelectTag from '../../components/dict/JSearchSelectTag'
import JSelectDepart from '../../components/jeecgbiz/JSelectDepart'
import JSelectAssets from '../../components/jeecgbiz/JSelectAssets'
import JImageUpload from '../../components/jeecg/JImageUpload'
import JSelectCangKu from '../../components/jeecgbiz/JSelectCangKu'
import { httpAction, postAction } from '../../api/manage'

export default {
  name: 'ZcglRecipientsList',
  mixins: [JeecgListMixin, activitiMixin],
  components: {
    ZcglRecipientsModal,
    ZcglPutAssetAdd,
    ZcglPutStorageModal,
    JSearchSelectTag, JSelectDepart, JSelectAssets, JImageUpload, JSelectCangKu
  },
  data () {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      addFlag:false,
      disableSubmit:false,
      description: '资产领用管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '单据号码',
          align: 'center',
          dataIndex: 'orderNo'
        },
        {
          title: '领用部门',
          align: 'center',
          dataIndex: 'newDepartment_dictText'
        },
        {
          title: '领用人',
          align: 'center',
          dataIndex: 'recipientsUser_dictText'
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '流程状态',
          align: 'center',
          dataIndex: 'processStatusText'
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        }
      ],
      url: {
        list: '/zcglRecipients/zcglRecipients/list',
        delete: '/zcglRecipients/zcglRecipients/delete',
        deleteBatch: '/zcglRecipients/zcglRecipients/deleteBatch',
        exportXlsUrl: '/zcglRecipients/zcglRecipients/exportXls',
        importExcelUrl: 'zcglRecipients/zcglRecipients/importExcel',
      },
      dictOptions: {},
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created () {
    let usercode = store.getters.userInfo.id

    // 过500毫秒调用
    setTimeout(() => {
      //admin
      if(usercode == '1199615897335095297'){
        setTimeout(() => {
          this.loadData();
        },1)

      }else{
        this.queryParam.recipientsUser = usercode
        this.loadData();
      }
    }, 1);


  },
  methods: {
    //自己的方法
    searchReset() {

      let usercode = store.getters.userInfo.id
      if(usercode == '1199615897335095297'){
        this.loadData();
      }else{
        this.queryParam = { recipientsUser: usercode }
        this.loadData();
      }
    },
    shuaxin(){


    },
    handleAdd: function () {
      // this.$refs.modalForm.add()
      // this.$refs.modalForm.title = '新增'
      // this.$refs.modalForm.disableSubmit = false
          let tableData = {
            routeName: '@/views/activiti/form/ZcglRecipientsAdd',
            tableName: 'zcgl_recipients',
            // tableId: res.result.id,
            tableId: "1590665592578457602",
          }
          tableData.routeName = '@/views/activiti/form/ZcglRecipientsAdd'
          // tableData.titleContent =  res.result.orderNo
          // this.processCreateCom(tableData, '发起资产领用' + name + '流程', '')
          this.processCreateCom(tableData, "物资申领明细", '')


      //先加一个空数据进行，保留id
      // postAction("/zcglRecipients/zcglRecipients/add",{}).then((res) => {
      //   if (res.success) {
      //     let tableData = {
      //       routeName: '@/views/activiti/form/ZcglRecipientsAdd',
      //       tableName: 'zcgl_recipients',
      //       // tableId: res.result.id,
      //       tableId: "1590665592578457602",
      //     }
      //     tableData.routeName = '@/views/activiti/form/ZcglRecipientsAdd'
      //     tableData.titleContent =  res.result.orderNo
      //     this.processCreateCom(tableData, '发起资产领用' + name + '流程', '')
      //   } else {
      //     this.$message.warning(res.message)
      //   }
      // }).finally(() => {
      //
      // })


    },
    chakan(record){

      this.addFlag = false
      this.handleEdit(record)
      this.$refs.modalForm.printData = record
      this.$refs.modalForm.disableSubmit = true
    },
    click (record, index) {
      return {
        on: {

          click: () => {

            this.addFlag = false
            this.handleEdit(record)
            this.$refs.modalForm.printData = record
            this.$refs.modalForm.disableSubmit = true
          }

        },

      }
    },
    modifyForm (r, name, type, ev) {

      let tableData = {
        routeName: '@/views/activiti/form/ZcglRecipientsAdd',
        tableName: 'zcgl_recipients',
        tableId: r.id,
        type: 0
      }
      if (type == 1) {
        tableData.routeName = '@/views/activiti/form/ZcglRecipientsAdd'
      }
      this.processCreateCom(tableData, '发起资产领用' + name + '流程', r.processStatus)
    },
    // initDictConfig () {
    // }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>